//
//  RWGiftCardViewController.m
//  RedWine
//
//  Created by Liufangfang on 2016/12/30.
//  Copyright © 2016年 HuiBangKe. All rights reserved.
//

#import "RWGiftCardViewController.h"
#import "RWGiftCardView.h"

@interface RWGiftCardViewController ()<RWGiftCardViewDelegate>

@property (nonatomic, strong) RWGiftCardView *giftCardV;

@end

@implementation RWGiftCardViewController

#pragma mark - View LifeCycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavigation];
    [self setGiftCardUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Load Datas

- (void)initObjects{
    
    
}

- (void)loadDatas{
    
    
}

#pragma mark - Config UI

- (void)setNavigation{
    
    self.title = @"礼品卡中心";
}

- (void)setGiftCardUI{
    
    _giftCardV = [[RWGiftCardView alloc] initWithFrame:CGRectMake(0, 0, FTY_SCREEN_WIDTH, FTY_SCREEN_HEIGHT)];
    [self.view addSubview:_giftCardV];
    _giftCardV.delegate = self;
    _giftCardV.backgroundColor = [UIColor whiteColor];
}

#pragma mark - Config Invoke Methods

#pragma mark - Notificaiton Method

#pragma mark - Notificaiton Invoke Methods

#pragma mark - <UITableViewDataSource>

#pragma mark - <UITableViewDelegate>

#pragma mark - <RWGiftCardViewDelegate>

- (void)cardActive:(UIButton *)btn{

    FTYUser *user = [FTYUser sharedUser];
    [FTYHTTPManager postInfoWithSubUrl:[NSString stringWithFormat:@"/shop/ybkapi.php?act=ybkapi&op=cardact&member_id=%@&member_mobile=%@&token=%@&verify=%@&sn=%@", user.userID, user.userPhoneNumber, user.userToken, _giftCardV.codeTF.text, _giftCardV.keyTF.text] parameters:nil block:^(id result, NSError *error) {
        
        if (!error) {
            
            NSInteger codeInfo = [[[result objectForKey:@"err"] objectForKey:@"errorcode"] integerValue];
            NSString *errorInfo = [[result objectForKey:@"err"] objectForKey:@"errorinfo"];
            NSDictionary *info = result[@"info"];
            if (0 == codeInfo) {

                [[FTYToastView alloc] addTitle:@"礼卡金已激活～" addView:self.view];
                [self activeSuccess:info];
            } else {
                [[FTYToastView alloc] addTitle:errorInfo addView:self.view];
            }
        } else {
            DLog(@"激活码请求失败：%@", error);
        }
    }];
}

#pragma mark - Private Invoke Methods

- (void)activeSuccess:(NSDictionary *)dic{

    [[NSNotificationCenter defaultCenter] postNotificationName:@"GiftCardActiveSuccessNotification" object:nil];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

@end
